package islenio;

import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import acciones.*;

import frsf.cidisi.faia.agent.Action;
import frsf.cidisi.faia.agent.Perception;
import frsf.cidisi.faia.agent.search.Problem;
import frsf.cidisi.faia.agent.search.SearchAction;
import frsf.cidisi.faia.agent.search.SearchBasedAgent;
import frsf.cidisi.faia.solver.search.AStarSearch;
import frsf.cidisi.faia.solver.search.BreathFirstSearch;
import frsf.cidisi.faia.solver.search.DepthFirstSearch;
import frsf.cidisi.faia.solver.search.IEstimatedCostFunction;
import frsf.cidisi.faia.solver.search.IStepCostFunction;
import frsf.cidisi.faia.solver.search.Search;
import frsf.cidisi.faia.solver.search.UniformCostSearch;

public class IslenioAgente  extends SearchBasedAgent {
	   public IslenioAgente() {

	        // Robot agent state
	        IslenioEstado agentState = new IslenioEstado();
	        super.setAgentState(agentState);
	        
	        // Robot agent goal
	        IslenioObjetivo goal = new IslenioObjetivo(agentState.Cenede);
	        
	        // Robot agent actions
	        Vector<SearchAction> actions = new Vector<SearchAction>();
	        actions.addElement(new TomarCofre());
	        actions.addElement(new IrAragaey());
	        actions.addElement(new IrAse());
	        actions.addElement(new IrErgintone());
	        actions.addElement(new IrBresol());
	        actions.addElement(new IrBulovoe());
	        actions.addElement(new IrCabe());
	        actions.addElement(new IrIcaedur());
	        actions.addElement(new IrMixocu());
	        actions.addElement(new IrPeregaey());
	        actions.addElement(new IrVinizaile());
	        actions.addElement(new IrCenede());


	        // Robot agent problem
	        Problem problem = new Problem(goal, agentState, actions);
	        this.setProblem(problem);
	    }

	    @Override
	    public Action selectAction() {

	    	//DepthFirstSearch strategy = new DepthFirstSearch();

	        IStepCostFunction costFunction = new FuncionCosto();
	      //  UniformCostSearch strategy = new UniformCostSearch(costFunction);
	        
	       IEstimatedCostFunction heuristic = new FuncionHeuristica();
	       AStarSearch strategy = new AStarSearch(costFunction, heuristic);
	        
	        Search searchSolver = new Search(strategy);

	        // Set the search tree to be written in an XML file
	        searchSolver.setVisibleTree(Search.EFAIA_TREE);

	        // Set the search solver
	        this.setSolver(searchSolver);

	        // Run the actions selection process
	        Action selectedAction = null;
	        try {
	            selectedAction = this.getSolver().solve(new Object[]{this.getProblem()});
	        } catch (Exception ex) {
	            Logger.getLogger(IslenioAgente.class.getName()).log(Level.SEVERE, null, ex);
	        }

	        // Return the selected action
	        return selectedAction;
	    }

	    @Override
	    public void see(Perception perception) {
	        this.getAgentState().updateState(perception);
	    }
	    
	   

}
